if myHero.charName ~= "Gangplank" then return end

local _QRange = 675
local _AttackRange = 125

function GetMMATarget()
    --if _G.MMA_Target ~= nil and _G.MMA_Target.type:lower() == "obj_ai_hero" then
	if _G.MMA_Target ~= nil then
        return _G.MMA_Target
    else
        ts:update()
        return ts.target
    end
end

function OnLoad()

	_Config = scriptConfig("GangPlank", "GangPlank")
	_Config:addParam("autoE", "Use Raise Morale", SCRIPT_PARAM_ONOFF, true)
	
	ts = TargetSelector(TARGET_LESS_CAST_PRIORITY, _QRange, true)
	ts.name = "GangPlank"
	_Config:addTS(ts)
	
end

function OnDraw()
	DrawCircle(myHero.x, myHero.y, myHero.z, _QRange, 0x8B18F0)
end
function OnTick()
	ts:update()
	_G.MMA_ConsideredTarget(_QRange)
	
	_QReady = (myHero:CanUseSpell(_Q) == READY)
	_WReady = (myHero:CanUseSpell(_W) == READY)
	_EReady = (myHero:CanUseSpell(_E) == READY)
	_RReady = (myHero:CanUseSpell(_R) == READY)
	
	_Target = GetMMATarget()
	
	if myHero.canMove == false then
		Packet("S_CAST", {spellId = _W, targetNetworkId = myHero.networkID}):send()
	end;
	
	if _G.MMA_LastHit or _G.MMA_LaneClear then
		for index, minion in pairs(minionManager(MINION_ENEMY, 625, myHero, MINION_SORT_HEALTH_ASC).objects) do
			Qdmg = getDmg("Q",minion,myHero)
			ADdmg = getDmg("AD",minion,myHero)
			Qdmg = Qdmg + ADdmg
			if _QReady then
				if GetDistance(minion) <= 625 and minion.health ~= nil and minion.health <= Qdmg and ValidTarget(minion) then
					CastSpell(_Q, minion)
				end
			end
		end
	end
				
	if _Target then
		if _G.MMA_HybridMode then
			if _QReady then
				Packet("S_CAST", {spellId = _Q, targetNetworkId = _Target.networkID}):send()
			end
		end
		if _G.MMA_Orbwalker then
			if _QReady then
				if _Config.autoE then
					if _EReady then
						CastSpell(_E)
					end
				end
				Packet("S_CAST", {spellId = _Q, targetNetworkId = _Target.networkID}):send()
			end
		end
	end
end